package com.liudadan.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Controller
@ResponseBody
public class UserController {
    @RequestMapping(value = {"/user/login"} , method = RequestMethod.POST)
    @ResponseBody
    public String login(){
        System.out.println("UserController.login");
        return "login success!!";
    }

    /**
     * 精准设置访问地址 /user/register
     */
    @RequestMapping(value = {"/user/register"},method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public String register(){
        System.out.println("UserController.register");
        return "register success!!";
    }
    @RequestMapping("/value")
    @ResponseBody
    public String setupForm(String name,int age){
        System.out.println("name = " + name + ", age = " + age);
        return name + age;
    }
    @GetMapping(value = "/mul")
    public Object mulForm(@RequestParam List<String> hbs){
        System.out.println("hbs = " + hbs);
        return hbs.toString();
    }
    /**
     * 方案4： 一名多值  key=value&key=value 你的爱好
     * /param/data3?hbs=chi&hbs=he&hbs=xuexi
     * 猜想：集合 （可以）或者 数组 (可以)
     * 注意： 必须添加@RequestParam String [] hbs
     */

    @RequestMapping("/data3")
    public String data3(@RequestParam String [] hbs){
        System.out.println("ParamController.data3");
        System.out.println("hbs = " + Arrays.toString(hbs));
        return Arrays.toString(hbs);
    }

}
